package com.wwj.springboot.controller;

import com.wwj.springboot.entity.CmfzUser;
import com.wwj.springboot.service.CmfzUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author wwj
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private CmfzUserService cus;

    @RequestMapping("selectByPage")
    public Map selectByPage(int page, int limit,String userName,String userTelphone){
        return cus.selectByPage(page, limit, userName,userTelphone);
    }


    @RequestMapping("selectOne")
    public CmfzUser selectOne(int id){
        return cus.selectOne(id);
    }

    @RequestMapping("addUser")
    public Map addUser(CmfzUser user){
        return cus.addUser(user);
    }
    @RequestMapping("deleteUser")
    public Map deleteUser(int id){
        return cus.deleteUser(id);
    }

    @RequestMapping("updateUser")
    public Map updateUser(CmfzUser user){
        return cus.updateUser(user);
    }

    @RequestMapping("selectBySexCount")
    public List<Map> selectBySexCount(){
        return cus.selectBySexCount();
    }

    @RequestMapping("selectByProvinceCount")
    public List<Map> selectByProvinceCount(){
        return cus.selectByProvinceCount();
    }

    @RequestMapping("selectByWeekCount")
    @ResponseBody
    public List<Map> selectByWeekCount(){
        return cus.selectByWeekCount();
    }

    /**
     * 一个方法查询多个图表
     */
    @RequestMapping("selectAllCount")
    public Map selectAllCount(){
        long start = System.currentTimeMillis();
        Map map = cus.selectAllCount();
        long end = System.currentTimeMillis();
        System.out.println(end-start+"ms");

        return map;
    }

    /**
     * 多线程
     * @return
     * @throws InterruptedException
     */
    @RequestMapping("selectAllCountByThread")
    public Map selectAllCountByThread() throws InterruptedException {
        long start = System.currentTimeMillis();
        Map map = cus.selectAllCountByThread();
        long end = System.currentTimeMillis();
        System.out.println(end-start+"ms"+"===================");
        return map;
    }

}
